﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace LoL
{

    abstract class Actor
    {
        private SpriteEffects spriteEffect;
        private Texture2D texture;
        private Rectangle frame;

        public float Depth { get; set; }

        public float Height()
        {
            return texture.Height*Scale.Y;
        }

        public float Width()
        {
            return texture.Width * Scale.X;
        }

        // Origin er hvor man skal begynne å tegne ting fra! Den må være lik for alle pga CD.
        public Vector2 Origin
        {
            get { return new Vector2((texture.Width * Scale.X)/2, (texture.Height * Scale.Y)/2); }             
        }

        public Vector2 Position
        {
            get;
            set;
        }

        public float Rotation { get; set; }

        public Vector2 Scale { get; set; }

        /*
         * Metode introdusert under kollisjonsdeteksjon. Returnerer
         * et rektangel som omslutter spriten. Overrides av Character-objekter.
         */
        public virtual Rectangle generateBoundingRectangle()
        {
            return new Rectangle((int) (Position.X - Origin.X), (int) (Position.Y - Origin.Y), (int)(texture.Width*Scale.X), (int)(texture.Height*Scale.Y));
        }


        public void flipHorizontally()
        {
            if (spriteEffect == SpriteEffects.FlipHorizontally)
                spriteEffect = SpriteEffects.None;
            else
                spriteEffect = SpriteEffects.FlipHorizontally;
        }

        public Actor(Vector2 startPosition)
        {
            spriteEffect = SpriteEffects.None;
            Depth = 0.0f;
            Scale = new Vector2(1, 1);
            Rotation = 0.0f;
            Position = startPosition;
        }

        public Texture2D getTexture()
        {
            return texture;
        }

        public void LoadContent(ContentManager theContentManager, string theAssetName)
        {
            texture = theContentManager.Load<Texture2D>(theAssetName);
            frame = new Rectangle(0, 0, texture.Width, texture.Height);
        }

        public virtual void Update(GameTime gameTime)
        {
            
        }


        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, Position, frame, Color.White, Rotation, Origin, Scale, spriteEffect, Depth);
        }
    }
}